package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.InAddPartrolOrderView;
import com.cloudsigns.factorymanager2.engineering.model.AddPartrolOrderModel;
import com.cloudsigns.factorymanager2.engineering.model.InAddPartrolOrderModel;

/**
 * Created by tony on 2018/5/5.
 */

public class AddPartrolOrderPresenter {
    private InAddPartrolOrderView view;
    private InAddPartrolOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public AddPartrolOrderPresenter(InAddPartrolOrderView view) {
        this.view = view;
        this.model = new AddPartrolOrderModel();
    }

    public void addPartrolOrder() {


        model.addPartrolOrder(view.getBeginDate(), view.getCompleteDate(), view.getMediaList(), view.getRegionId(), view.getRegionName(), new AddPartrolOrderModel.OnAddPartrolOrderListener() {
            @Override
            public void addPartrolOrderSuccessed(final String id) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addPartrolOrderSuccessed(id);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void addPartrolOrderFailed(final String desc) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });

    }
}
